<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="author" content="WD">





<title>Forest数据分析及可视化 | WD&#39;s blog</title>



    <link rel="icon" href="/favicon1.ico">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/js/script.js"></script>
    
    <script src="/js/tocbot.min.js"></script>
    
    <script src="/js/snow.js"></script>
    



    
    
        
    


<meta name="generator" content="Hexo 5.4.0"></head>
<body>
    <div class="wrapper">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo"><a href="/">WD&#39;s Blog</a></div>
            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
                <input id="switch_default" type="checkbox" class="switch_default">
                <label for="switch_default" class="toggleBtn"></label>
            </div>
        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/">WD&#39;s Blog</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
            </div>
        </div>
    </nav>

</header>
<script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>
        <div class="main">
            <div class="container">
    
    
        <div class="post-toc">
    <div class="tocbot-list">
    </div>
    <div class="tocbot-list-menu">
        <a class="tocbot-toc-expand" onclick="expand_toc()">Expand all</a>
        <a onclick="go_top()">Back to top</a>
        <a onclick="go_bottom()">Go to bottom</a>
    </div>
</div>

<script>
    document.ready(
        function () {
            tocbot.init({
                tocSelector: '.tocbot-list',
                contentSelector: '.post-content',
                headingSelector: 'h1, h2, h3, h4, h5',
                collapseDepth: 1,
                orderedList: false,
                scrollSmooth: true,
            })
        }
    )

    function expand_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 6,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "collapse_toc()");
        b.innerHTML = "Collapse all"
    }

    function collapse_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 1,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "expand_toc()");
        b.innerHTML = "Expand all"
    }

    function go_top() {
        window.scrollTo(0, 0);
    }

    function go_bottom() {
        window.scrollTo(0, document.body.scrollHeight);
    }

</script>
    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">Forest数据分析及可视化</h1>
            
                <div class="post-meta">
                    
                        Author: <a itemprop="author" rel="author" href="/about/">WD</a>
                     &nbsp;

                    
                        <span class="post-time">
                        Date: <a href="#">July 17, 2020&nbsp;&nbsp;10:13:51</a>
                        </span>
                     &nbsp;
                    
                        <span class="post-category">
                    Category:
                            
                                <a href="/categories/Python/">Python</a>
                            
                        </span>
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <br>
    <span id="busuanzi_container_site_pv">总阅读量:<a href="#"><span id="busuanzi_value_page_pv"></span></a>次</span>&nbsp;
    <span class="post-count">文章字数:<a href="#">3.2k</span></a>&nbsp;
     <span class="post-count">阅读时长:<a href="#">15</span>min</a>
                    
                </div>
            
        </header>

        <div class="post-content">
            <h2 id="说在前面"><a href="#说在前面" class="headerlink" title="说在前面"></a>说在前面</h2><ul>
<li><p>这次python作业是数据分析及可视化，这里我采用的是一个APP “Forest” ，从软件中导出 “Plants of forest.csv”，这是csv格式的数据集</p>
</li>
<li><p>Forest是一个让你规划时间，放下手机保持专注的APP，当需要专注的时候就种下一棵树并倒计时，时间结束，树就会长大，如果中途离开Forest，树就会枯死，最终所有种树记录都会保存，并且可以导出csv文件。</p>
</li>
<li><p>这里推荐一下Forest的官网，有需要的小伙伴可以去下载试试，可以提高学习效率。<a target="_blank" rel="noopener" href="https://www.forestapp.cc/">https://www.forestapp.cc/</a></p>
<p>下面是种树后的截图：（来源官网）</p>
</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/20200717101206984.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1594949630328"></p>
<h2 id="1-导入csv数据集"><a href="#1-导入csv数据集" class="headerlink" title="1.导入csv数据集"></a>1.导入csv数据集</h2><ul>
<li><p>下面是我截取的部分csv数据集：</p>
<p><img src="https://img-blog.csdnimg.cn/20200717101220334.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1594950128589"></p>
</li>
<li><p>首先可以看出这里有StartTime(开始种树的时间)、EndTime(结束种树的时间)、Tag(标签，里面有”学习”、”休息”、”睡觉”等)、Note(自己设置的备注)、TreeType(每次种树的种类)、IsSuccess(是否种树成功)。</p>
</li>
<li><p>下面首先将该csv文件读进来，使用pandas中的read_csv()方法将其读进来保存到data中，之后可以用data[‘Tag’]取出标签这一列，其余列也是类似，这样就可以导入csv文件数据了。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">data = pd.read_csv(<span class="string">&#x27;Plants of forest.csv&#x27;</span>)</span><br><span class="line">tag = data[<span class="string">&#x27;Tag&#x27;</span>]</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="2-分析种树种类"><a href="#2-分析种树种类" class="headerlink" title="2.分析种树种类"></a>2.分析种树种类</h2><ul>
<li><p>先对种树的种类进行分析：用<code>list(data[‘TreeType’])</code>取出TreeType这一列数据并转化为列表，这里定义一个字典用来统计不同种类树的个数，遍历列表中每一个数据，使用count()方法统计个数并和该类型的种类组成一个键值对存到字典中，之后用sum(tree_dic.values)对种下的数目总数进行统计，并用sort方法对字典中树木类型的数量进行排序并打印输出。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">tree_type_analyse</span>(<span class="params">data</span>):</span></span><br><span class="line">    <span class="string">&quot;&quot;&quot;分析种树种类&quot;&quot;&quot;</span></span><br><span class="line">	tree_type = <span class="built_in">list</span>(data[<span class="string">&#x27;Tree Type&#x27;</span>])</span><br><span class="line">	tree_dic = &#123;&#125;</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> tree_type:</span><br><span class="line">		tree_dic[i] = tree_type.count(i)</span><br><span class="line">	tree_list = <span class="built_in">list</span>(tree_dic.items())</span><br><span class="line">	tree_list.sort(key= <span class="keyword">lambda</span> x:x[<span class="number">1</span>], reverse=<span class="literal">True</span>)</span><br><span class="line">	tree_type_count = <span class="built_in">len</span>(tree_list)</span><br><span class="line">	tree_count = <span class="built_in">sum</span>(tree_dic.values())</span><br><span class="line">	sorted_tree = []</span><br><span class="line">	sorted_count = []</span><br><span class="line">	</span><br><span class="line">	<span class="built_in">print</span>(<span class="string">&#x27;you have planted &#123;0&#125; trees, There are &#123;1&#125; types of trees&#x27;</span>.<span class="built_in">format</span>(tree_count, tree_type_count))</span><br><span class="line">	<span class="built_in">print</span> (<span class="string">&#x27;\tTree Type \t\t\t counts&#x27;</span>)</span><br><span class="line">	<span class="built_in">print</span> (<span class="string">&#x27;=================================&#x27;</span>)</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="built_in">len</span>(tree_list)):</span><br><span class="line">		tree, count = tree_list[i]</span><br><span class="line">		<span class="keyword">if</span> i &lt;= <span class="number">9</span>:</span><br><span class="line">			sorted_tree.append(tree)</span><br><span class="line">			sorted_count.append(count)</span><br><span class="line">		<span class="built_in">print</span>(<span class="string">&quot;&#123;0:&lt;30&#125;&#123;1:&lt;5&#125;&quot;</span>.<span class="built_in">format</span>(tree, count))</span><br></pre></td></tr></table></figure>
<p>下面是打印输出结果：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">you have planted <span class="number">433</span> trees, There are <span class="number">40</span> types of trees</span><br><span class="line">	Tree <span class="type">Type</span> 			 counts</span><br><span class="line">=================================</span><br><span class="line">Moon Tree                     <span class="number">82</span>   </span><br><span class="line">Maple                         <span class="number">49</span>   </span><br><span class="line">Cake Tree                     <span class="number">45</span>   </span><br><span class="line">Weeping Willow                <span class="number">37</span>   </span><br><span class="line">Cedar                         <span class="number">24</span>   </span><br><span class="line">Oak Tree                      <span class="number">19</span>   </span><br><span class="line">Starburst Tree                <span class="number">16</span>   </span><br><span class="line">Candy Tree                    <span class="number">15</span>   </span><br><span class="line">Earth Day Tree                <span class="number">13</span>   </span><br><span class="line">Blueberry Cake                <span class="number">11</span>   </span><br><span class="line">Matcha Azuki Cake             <span class="number">11</span>   </span><br><span class="line">Blue Oak Tree                 <span class="number">10</span>   </span><br><span class="line">Ginkgo                        <span class="number">9</span>    </span><br><span class="line">Pink Oak Tree                 <span class="number">8</span>    </span><br><span class="line">Sunflower                     <span class="number">8</span>    </span><br><span class="line">Four-Leaf Clover              <span class="number">7</span>    </span><br><span class="line">Cherry Cheese Cake            <span class="number">6</span>    </span><br><span class="line">Celestial Tree                <span class="number">6</span>    </span><br><span class="line">Bush                          <span class="number">5</span>    </span><br><span class="line">Banana                        <span class="number">5</span>    </span><br><span class="line">Carnation                     <span class="number">5</span>    </span><br><span class="line">Rose                          <span class="number">5</span>    </span><br><span class="line">Tiramisu                      <span class="number">4</span>    </span><br><span class="line">Wisteria                      <span class="number">4</span>    </span><br><span class="line">Purple Oak Tree               <span class="number">4</span>    </span><br><span class="line">Forest Spirit                 <span class="number">4</span>    </span><br><span class="line">Strawberry Chiffon Cake       <span class="number">3</span>    </span><br><span class="line">Lemon Cake                    <span class="number">2</span>    </span><br><span class="line">Lemon Tree                    <span class="number">2</span>    </span><br><span class="line">Space Tree                    <span class="number">2</span>    </span><br><span class="line">Coconut Tree                  <span class="number">2</span>    </span><br><span class="line">Rainbow Flower                <span class="number">2</span>    </span><br><span class="line">Black Forest Cake             <span class="number">1</span>    </span><br><span class="line">Chocolate Strawberry Cake     <span class="number">1</span>    </span><br><span class="line">Yellow Oak Tree               <span class="number">1</span>    </span><br><span class="line">Cat-tail Willow               <span class="number">1</span>    </span><br><span class="line">Blue Flower                   <span class="number">1</span>    </span><br><span class="line">Cherry Blossom                <span class="number">1</span>    </span><br><span class="line">Flourishing Grass             <span class="number">1</span>    </span><br><span class="line">Flower Tree                   <span class="number">1</span>    </span><br></pre></td></tr></table></figure>
</li>
<li><p>通过运行结果可以看到我一共种了433棵树，一共有40个种类，其中种植数量最多的是”Moon Tree”。</p>
</li>
<li><p>之后将前10的数目种类个数用直方图的形式绘制出来，这里就用到了plt.bar()方法绘制直方图。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">plt.bar(sorted_tree,sorted_count,color=<span class="string">&#x27;lightskyblue&#x27;</span>)</span><br><span class="line">plt.xlabel(<span class="string">&#x27;Tree Type&#x27;</span>)</span><br><span class="line">plt.ylabel(<span class="string">&#x27;counts&#x27;</span>)</span><br><span class="line">plt.title(<span class="string">&#x27;Number of top ten tree types&#x27;</span>)</span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure>
<p>下面是绘制的种植数量前10的直方图结果：</p>
<p><img src="https://img-blog.csdnimg.cn/20200717101234835.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1594950751481"></p>
</li>
</ul>
<h2 id="3-分析种树标签"><a href="#3-分析种树标签" class="headerlink" title="3.分析种树标签"></a>3.分析种树标签</h2><ul>
<li><p>下面对树木的Tag和Time进行分析，观察我主要种树来做什么事情了分别用了多少时间，首先还是通过<code>list(data[‘Tag’])</code>和<code>list(data[‘Start Time’])</code>、<code>list(data[‘End Time’])</code>获取这些标签的每一列数据。</p>
</li>
<li><p>之后定义<code>duration=[]</code>，用来存放每一次种树的持续时间，<code>time1=[]</code>和<code>time2=[]</code>用来存放每一次的起始时间和结束时间，这里我采用的计时单位是秒，之后遍历Strat Time 和 End Time，对其时间字符串进行split(‘:’)分割成时分秒的形式，然后计算总秒钟，将两个time2和time1列表对应位相减就得到每一次种树的持续时间，存放到duration列表中。</p>
</li>
<li><p>接着和之前的方法一样定义一个dic_tag字典，遍历所有的Tag，将他们的持续时间加起来构成一个键值对存到字典中，然后打印出来该字典；其次我还使用了plt.pie()绘制出来不同Tag所对应时间的饼图。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">tree_tag_analyse</span>(<span class="params">data</span>):</span></span><br><span class="line">    <span class="string">&quot;&quot;&quot;分析种树标签&quot;&quot;&quot;</span></span><br><span class="line">	tree_tag = <span class="built_in">list</span>(data[<span class="string">&#x27;Tag&#x27;</span>])</span><br><span class="line">	start_time = <span class="built_in">list</span>(data[<span class="string">&#x27;Start Time&#x27;</span>])</span><br><span class="line">	end_time = <span class="built_in">list</span>(data[<span class="string">&#x27;End Time&#x27;</span>])</span><br><span class="line">	duration = []</span><br><span class="line">	time1 = []</span><br><span class="line">	time2 = []</span><br><span class="line">	dic_tag = &#123;&#125;</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> start_time:</span><br><span class="line">		x = i.split(<span class="string">&#x27; &#x27;</span>)[<span class="number">3</span>].split(<span class="string">&#x27;:&#x27;</span>)</span><br><span class="line">		time1.append(<span class="built_in">int</span>(x[<span class="number">0</span>])*<span class="number">60</span>*<span class="number">60</span> + <span class="built_in">int</span>(x[<span class="number">1</span>])* <span class="number">60</span> + <span class="built_in">int</span>(x[<span class="number">2</span>]))</span><br><span class="line">	<span class="comment">#print(time1)</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> end_time:</span><br><span class="line">		x = i.split(<span class="string">&#x27; &#x27;</span>)[<span class="number">3</span>].split(<span class="string">&#x27;:&#x27;</span>)</span><br><span class="line">		time2.append(<span class="built_in">int</span>(x[<span class="number">0</span>])*<span class="number">60</span>*<span class="number">60</span> + <span class="built_in">int</span>(x[<span class="number">1</span>])* <span class="number">60</span> + <span class="built_in">int</span>(x[<span class="number">2</span>]))</span><br><span class="line">	<span class="comment">#print(time2)</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="built_in">len</span>(time1)):</span><br><span class="line">		<span class="keyword">if</span> time1[i] &gt; time2[i]:</span><br><span class="line">			duration.append(<span class="number">24</span>*<span class="number">60</span>*<span class="number">60</span> - time1[i] + time2[i])</span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			duration.append(time2[i] - time1[i])</span><br><span class="line">	<span class="comment">#print(duration)</span></span><br><span class="line">	total_duration = <span class="built_in">sum</span>(duration)</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="built_in">len</span>(duration)):</span><br><span class="line">		<span class="keyword">if</span> tree_tag[i] <span class="keyword">in</span> dic_tag.keys():</span><br><span class="line">			dic_tag[tree_tag[i]] += duration[i]/<span class="number">60</span>/<span class="number">60</span></span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			dic_tag[tree_tag[i]] = duration[i]/<span class="number">60</span>/<span class="number">60</span></span><br><span class="line">	<span class="built_in">print</span>(dic_tag) </span><br><span class="line">	explode=[<span class="number">0.01</span>]*<span class="built_in">len</span>(dic_tag.keys())</span><br><span class="line">	color = [<span class="string">&#x27;grey&#x27;</span>,<span class="string">&#x27;salmon&#x27;</span>,<span class="string">&#x27;lime&#x27;</span>,<span class="string">&#x27;lightskyblue&#x27;</span>,<span class="string">&#x27;gold&#x27;</span>,<span class="string">&#x27;red&#x27;</span>,<span class="string">&#x27;yellow&#x27;</span>,<span class="string">&#x27;green&#x27;</span>,<span class="string">&#x27;silver&#x27;</span>,<span class="string">&#x27;pink&#x27;</span>]</span><br><span class="line">plt.pie(dic_tag.values(),explode=explode,labels=dic_tag.keys(),autopct=<span class="string">&#x27;%1.1f%%&#x27;</span>,colors=color)</span><br><span class="line">	plt.title(<span class="string">&#x27;Tag distribution&#x27;</span>)</span><br><span class="line">	plt.show()</span><br><span class="line">	<span class="keyword">return</span> duration</span><br></pre></td></tr></table></figure>
<p>下面是输出的结果：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;<span class="string">&#x27;Unset&#x27;</span>: <span class="number">0.46416666666666667</span>, <span class="string">&#x27;学习&#x27;</span>: <span class="number">188.2266666666667</span>, <span class="string">&#x27;休息&#x27;</span>: <span class="number">29.583333333333336</span>, <span class="string">&#x27;睡觉&#x27;</span>: <span class="number">323.9866666666667</span>, <span class="string">&#x27;洗漱&#x27;</span>: <span class="number">2.0572222222222223</span>, <span class="string">&#x27;上课&#x27;</span>: <span class="number">204.68583333333333</span>, <span class="string">&#x27;运动&#x27;</span>: <span class="number">6.833333333333336</span>, <span class="string">&#x27;吃饭&#x27;</span>: <span class="number">4.333333333333334</span>, <span class="string">&#x27;其他&#x27;</span>: <span class="number">3.8333333333333335</span>, <span class="string">&#x27;工作&#x27;</span>: <span class="number">11.0</span>&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/20200717101247218.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1594951096537"></p>
</li>
<li><p>从输出结果可以看出我的时间基本用在了睡觉、学习、上课这三个方面，少部分用来休息、洗漱、运动、其他，这也反应了我平时的真实状况，学习和上课时间较多，运动时间少。这里睡觉用了323小时，学习用了188小时。</p>
</li>
</ul>
<h2 id="4-种植树木的成功率"><a href="#4-种植树木的成功率" class="headerlink" title="4.种植树木的成功率"></a>4.种植树木的成功率</h2><ul>
<li><p>之后我又对种植数目的成功率进行了统计，这里就用到数据的IsSuccess这一列数据，通过遍历该数据，统计True和False的个数，并将成功率进行打印输出。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">success_rate_analyse</span>(<span class="params">data</span>):</span></span><br><span class="line">    <span class="string">&quot;&quot;&quot;种植树木的成功率&quot;&quot;&quot;</span></span><br><span class="line">	tree_is_success = <span class="built_in">list</span>(data[<span class="string">&#x27;Is Success&#x27;</span>])</span><br><span class="line">	success = tree_is_success.count(<span class="literal">True</span>)</span><br><span class="line">	fail = tree_is_success.count(<span class="literal">False</span>)</span><br><span class="line">	<span class="built_in">print</span>(<span class="string">&#x27;&#123;0&#125; trees were planted: &#123;1&#125; successful and &#123;2&#125; failed&#x27;</span>.<span class="built_in">format</span>(<span class="built_in">len</span>(tree_is_success), success, fail))</span><br><span class="line">	<span class="built_in">print</span>(<span class="string">&#x27;the success rate is &#123;0:.2f&#125;%&#x27;</span>.<span class="built_in">format</span>(success/<span class="built_in">len</span>(tree_is_success)*<span class="number">100</span>))</span><br></pre></td></tr></table></figure>
<p>下面是输出的结果，可以发现一共种了433棵树，其中425棵成功了，8棵失败了，成功率高达98.15%。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">433</span> trees were planted: <span class="number">425</span> successful <span class="keyword">and</span> <span class="number">8</span> failed</span><br><span class="line">the success rate <span class="keyword">is</span> <span class="number">98.15</span>%</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="5-基于周和月的种树时间分析"><a href="#5-基于周和月的种树时间分析" class="headerlink" title="5.基于周和月的种树时间分析"></a>5.基于周和月的种树时间分析</h2><ul>
<li><p>最后我又以月份为衡量单位和以周为衡量单位对我整体种树的时间进行了分析，这里依然是对Start Time和End Time中的字符串进行split，分理出月份和星期数，然后也是定义了两个字典分别来存储每一月的种植时间总数和每一星期的种植时间总数，由于方法和前面的类似，在此不再赘述。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">day_and_mouth_analyse</span>(<span class="params">data, duration</span>):</span></span><br><span class="line">    <span class="string">&quot;&quot;&quot;基于周和月的种树时间分析&quot;&quot;&quot;</span></span><br><span class="line">	start_time = <span class="built_in">list</span>(data[<span class="string">&#x27;Start Time&#x27;</span>])</span><br><span class="line">	mouth = []</span><br><span class="line">	week = []</span><br><span class="line">	dic_mouth = &#123;<span class="string">&#x27;Jan&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Feb&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Mar&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Apr&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;May&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Jun&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Jul&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Aug&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Sep&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Oct&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Nov&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Dec&#x27;</span>:<span class="number">0</span>&#125;</span><br><span class="line">	dic_week = &#123;<span class="string">&#x27;Mon&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Tue&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Wed&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Thu&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Fri&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Sat&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Sun&#x27;</span>:<span class="number">0</span>,&#125;</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> start_time:</span><br><span class="line">		mouth.append(i.split(<span class="string">&#x27; &#x27;</span>)[<span class="number">1</span>])</span><br><span class="line">		week.append(i.split(<span class="string">&#x27; &#x27;</span>)[<span class="number">0</span>])</span><br><span class="line">	<span class="comment">#print(mouth)</span></span><br><span class="line">	<span class="comment">#print(week)</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="built_in">len</span>(mouth)):</span><br><span class="line">		dic_mouth[mouth[i]] += duration[i]/<span class="number">60</span>/<span class="number">60</span></span><br><span class="line">		dic_week[week[i]] += duration[i]/<span class="number">60</span>/<span class="number">60</span> </span><br><span class="line">	<span class="built_in">print</span>(dic_mouth)</span><br><span class="line">	<span class="built_in">print</span>(dic_week)</span><br><span class="line">	plt.subplot(<span class="number">1</span>,<span class="number">2</span>,<span class="number">1</span>)</span><br><span class="line">	plt.plot(dic_mouth.keys(), dic_mouth.values(),color=<span class="string">&#x27;red&#x27;</span>,marker=<span class="string">&#x27;o&#x27;</span>,markerfacecolor=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&#x27;mouth&#x27;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&#x27;hour&#x27;</span>)</span><br><span class="line">	plt.title(<span class="string">&#x27;Month duration curve&#x27;</span>)</span><br><span class="line">	plt.subplot(<span class="number">1</span>,<span class="number">2</span>,<span class="number">2</span>)</span><br><span class="line">	plt.plot(dic_week.keys(), dic_week.values(),color=<span class="string">&#x27;blue&#x27;</span>,marker=<span class="string">&#x27;o&#x27;</span>,markerfacecolor=<span class="string">&#x27;red&#x27;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&#x27;week&#x27;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&#x27;hour&#x27;</span>)</span><br><span class="line">	plt.title(<span class="string">&#x27;Week duration curve&#x27;</span>)</span><br><span class="line">	plt.show()</span><br></pre></td></tr></table></figure>
<p>下面是最终的输出结果：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#月份输出结果</span></span><br><span class="line">&#123;<span class="string">&#x27;Jan&#x27;</span>: <span class="number">0</span>, <span class="string">&#x27;Feb&#x27;</span>: <span class="number">49.416666666666664</span>, <span class="string">&#x27;Mar&#x27;</span>: <span class="number">385.08722222222224</span>, <span class="string">&#x27;Apr&#x27;</span>: <span class="number">286.83333333333337</span>, <span class="string">&#x27;May&#x27;</span>: <span class="number">31.750000000000004</span>, <span class="string">&#x27;Jun&#x27;</span>: <span class="number">3.75</span>, <span class="string">&#x27;Jul&#x27;</span>: <span class="number">0</span>, <span class="string">&#x27;Aug&#x27;</span>: <span class="number">0</span>, <span class="string">&#x27;Sep&#x27;</span>: <span class="number">0</span>, <span class="string">&#x27;Oct&#x27;</span>: <span class="number">0</span>, <span class="string">&#x27;Nov&#x27;</span>: <span class="number">0</span>, <span class="string">&#x27;Dec&#x27;</span>: <span class="number">18.166666666666668</span>&#125;</span><br><span class="line"><span class="comment">#周输出结果</span></span><br><span class="line">&#123;<span class="string">&#x27;Mon&#x27;</span>: <span class="number">129.18694444444446</span>, <span class="string">&#x27;Tue&#x27;</span>: <span class="number">139.7863888888889</span>, <span class="string">&#x27;Wed&#x27;</span>: <span class="number">118.59722222222223</span>, <span class="string">&#x27;Thu&#x27;</span>: <span class="number">104.75</span>, <span class="string">&#x27;Fri&#x27;</span>: <span class="number">88.0</span>, <span class="string">&#x27;Sat&#x27;</span>: <span class="number">91.0</span>, <span class="string">&#x27;Sun&#x27;</span>: <span class="number">103.68333333333334</span>&#125;</span><br></pre></td></tr></table></figure>
<p>下面是绘制的他们的折线图：</p>
<p><img src="https://img-blog.csdnimg.cn/20200717101300216.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="1594951530140"></p>
</li>
<li><p>由折线图可以看出，我2、3、4、5月份种树花的时间最多，其余的月份较少，这是因为我用这个软件才刚刚几个月，所以其他月份没有记录，从每一周的统计结果来看，我在星期五和周末花的时间较少，这也比较符合我的正常生活规律，一般周末都没有课程，所以时间较少。</p>
</li>
</ul>
<h2 id="6-总结"><a href="#6-总结" class="headerlink" title="6.总结"></a>6.总结</h2><ul>
<li>以上就是我对“Plants of forest.csv”数据集的分析结果，整体来说还是比较符合实际的，也将里面各个标签的内容都一一做了分析。包括通过对时间的分析，我也知道了我的大部分时间都用到了哪里，也提醒我后面加强锻炼。</li>
<li>最后这个软件确实会提高自己的工作学习效率，减少看手机的时间，有需要的小伙伴可以试一下。</li>
</ul>
<h2 id="附源代码"><a href="#附源代码" class="headerlink" title="附源代码"></a>附源代码</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">tree_type_analyse</span>(<span class="params">data</span>):</span></span><br><span class="line">	tree_type = <span class="built_in">list</span>(data[<span class="string">&#x27;Tree Type&#x27;</span>])</span><br><span class="line">	tree_dic = &#123;&#125;</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> tree_type:</span><br><span class="line">		tree_dic[i] = tree_type.count(i)</span><br><span class="line">	tree_list = <span class="built_in">list</span>(tree_dic.items())</span><br><span class="line">	tree_list.sort(key= <span class="keyword">lambda</span> x:x[<span class="number">1</span>], reverse=<span class="literal">True</span>)</span><br><span class="line">	tree_type_count = <span class="built_in">len</span>(tree_list)</span><br><span class="line">	tree_count = <span class="built_in">sum</span>(tree_dic.values())</span><br><span class="line">	sorted_tree = []</span><br><span class="line">	sorted_count = []</span><br><span class="line">	</span><br><span class="line">	<span class="built_in">print</span>(<span class="string">&#x27;you have planted &#123;0&#125; trees, There are &#123;1&#125; types of trees&#x27;</span>.<span class="built_in">format</span>(tree_count, tree_type_count))</span><br><span class="line">	<span class="built_in">print</span> (<span class="string">&#x27;\tTree Type \t\t\t counts&#x27;</span>)</span><br><span class="line">	<span class="built_in">print</span> (<span class="string">&#x27;=================================&#x27;</span>)</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="built_in">len</span>(tree_list)):</span><br><span class="line">		tree, count = tree_list[i]</span><br><span class="line">		<span class="keyword">if</span> i &lt;= <span class="number">9</span>:</span><br><span class="line">			sorted_tree.append(tree)</span><br><span class="line">			sorted_count.append(count)</span><br><span class="line">		<span class="built_in">print</span>(<span class="string">&quot;&#123;0:&lt;30&#125;&#123;1:&lt;5&#125;&quot;</span>.<span class="built_in">format</span>(tree, count))</span><br><span class="line">	plt.bar(sorted_tree,sorted_count,color=<span class="string">&#x27;lightskyblue&#x27;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&#x27;Tree Type&#x27;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&#x27;counts&#x27;</span>)</span><br><span class="line">	plt.title(<span class="string">&#x27;Number of top ten tree types&#x27;</span>)</span><br><span class="line">	plt.show()</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">tree_tag_analyse</span>(<span class="params">data</span>):</span></span><br><span class="line">	tree_tag = <span class="built_in">list</span>(data[<span class="string">&#x27;Tag&#x27;</span>])</span><br><span class="line">	start_time = <span class="built_in">list</span>(data[<span class="string">&#x27;Start Time&#x27;</span>])</span><br><span class="line">	end_time = <span class="built_in">list</span>(data[<span class="string">&#x27;End Time&#x27;</span>])</span><br><span class="line">	duration = []</span><br><span class="line">	time1 = []</span><br><span class="line">	time2 = []</span><br><span class="line">	dic_tag = &#123;&#125;</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> start_time:</span><br><span class="line">		x = i.split(<span class="string">&#x27; &#x27;</span>)[<span class="number">3</span>].split(<span class="string">&#x27;:&#x27;</span>)</span><br><span class="line">		time1.append(<span class="built_in">int</span>(x[<span class="number">0</span>])*<span class="number">60</span>*<span class="number">60</span> + <span class="built_in">int</span>(x[<span class="number">1</span>])* <span class="number">60</span> + <span class="built_in">int</span>(x[<span class="number">2</span>]))</span><br><span class="line">	<span class="comment">#print(time1)</span></span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> end_time:</span><br><span class="line">		x = i.split(<span class="string">&#x27; &#x27;</span>)[<span class="number">3</span>].split(<span class="string">&#x27;:&#x27;</span>)</span><br><span class="line">		time2.append(<span class="built_in">int</span>(x[<span class="number">0</span>])*<span class="number">60</span>*<span class="number">60</span> + <span class="built_in">int</span>(x[<span class="number">1</span>])* <span class="number">60</span> + <span class="built_in">int</span>(x[<span class="number">2</span>]))</span><br><span class="line">	<span class="comment">#print(time2)</span></span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="built_in">len</span>(time1)):</span><br><span class="line">		<span class="keyword">if</span> time1[i] &gt; time2[i]:</span><br><span class="line">			duration.append(<span class="number">24</span>*<span class="number">60</span>*<span class="number">60</span> - time1[i] + time2[i])</span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			duration.append(time2[i] - time1[i])</span><br><span class="line">	<span class="comment">#print(duration)</span></span><br><span class="line"></span><br><span class="line">	total_duration = <span class="built_in">sum</span>(duration)</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="built_in">len</span>(duration)):</span><br><span class="line">		<span class="keyword">if</span> tree_tag[i] <span class="keyword">in</span> dic_tag.keys():</span><br><span class="line">			dic_tag[tree_tag[i]] += duration[i]/<span class="number">60</span>/<span class="number">60</span></span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			dic_tag[tree_tag[i]] = duration[i]/<span class="number">60</span>/<span class="number">60</span></span><br><span class="line">	<span class="built_in">print</span>(dic_tag) </span><br><span class="line"></span><br><span class="line">	explode=[<span class="number">0.01</span>]*<span class="built_in">len</span>(dic_tag.keys())</span><br><span class="line">	color = [<span class="string">&#x27;grey&#x27;</span>,<span class="string">&#x27;salmon&#x27;</span>,<span class="string">&#x27;lime&#x27;</span>,<span class="string">&#x27;lightskyblue&#x27;</span>,<span class="string">&#x27;gold&#x27;</span>,<span class="string">&#x27;red&#x27;</span>,<span class="string">&#x27;yellow&#x27;</span>,<span class="string">&#x27;green&#x27;</span>,<span class="string">&#x27;silver&#x27;</span>,<span class="string">&#x27;pink&#x27;</span>]</span><br><span class="line">	plt.pie(dic_tag.values(),explode=explode,labels=dic_tag.keys(),autopct=<span class="string">&#x27;%1.1f%%&#x27;</span>,colors=color)</span><br><span class="line">	plt.title(<span class="string">&#x27;Tag distribution&#x27;</span>)</span><br><span class="line">	plt.show()</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> duration</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">success_rate_analyse</span>(<span class="params">data</span>):</span></span><br><span class="line">	tree_is_success = <span class="built_in">list</span>(data[<span class="string">&#x27;Is Success&#x27;</span>])</span><br><span class="line">	success = tree_is_success.count(<span class="literal">True</span>)</span><br><span class="line">	fail = tree_is_success.count(<span class="literal">False</span>)</span><br><span class="line">	<span class="built_in">print</span>(<span class="string">&#x27;&#123;0&#125; trees were planted: &#123;1&#125; successful and &#123;2&#125; failed&#x27;</span>.<span class="built_in">format</span>(<span class="built_in">len</span>(tree_is_success), success, fail))</span><br><span class="line">	<span class="built_in">print</span>(<span class="string">&#x27;the success rate is &#123;0:.2f&#125;%&#x27;</span>.<span class="built_in">format</span>(success/<span class="built_in">len</span>(tree_is_success)*<span class="number">100</span>))</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">day_and_mouth_analyse</span>(<span class="params">data, duration</span>):</span></span><br><span class="line">	start_time = <span class="built_in">list</span>(data[<span class="string">&#x27;Start Time&#x27;</span>])</span><br><span class="line">	mouth = []</span><br><span class="line">	week = []</span><br><span class="line">	dic_mouth = &#123;<span class="string">&#x27;Jan&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Feb&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Mar&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Apr&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;May&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Jun&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Jul&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Aug&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Sep&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Oct&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Nov&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Dec&#x27;</span>:<span class="number">0</span>&#125;</span><br><span class="line">	dic_week = &#123;<span class="string">&#x27;Mon&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Tue&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Wed&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Thu&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Fri&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Sat&#x27;</span>:<span class="number">0</span>, <span class="string">&#x27;Sun&#x27;</span>:<span class="number">0</span>,&#125;</span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> start_time:</span><br><span class="line">		mouth.append(i.split(<span class="string">&#x27; &#x27;</span>)[<span class="number">1</span>])</span><br><span class="line">		week.append(i.split(<span class="string">&#x27; &#x27;</span>)[<span class="number">0</span>])</span><br><span class="line">	<span class="comment">#print(mouth)</span></span><br><span class="line">	<span class="comment">#print(week)</span></span><br><span class="line">	<span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="built_in">len</span>(mouth)):</span><br><span class="line">		dic_mouth[mouth[i]] += duration[i]/<span class="number">60</span>/<span class="number">60</span></span><br><span class="line">		dic_week[week[i]] += duration[i]/<span class="number">60</span>/<span class="number">60</span> </span><br><span class="line">	<span class="built_in">print</span>(dic_mouth)</span><br><span class="line">	<span class="built_in">print</span>(dic_week)</span><br><span class="line">	plt.subplot(<span class="number">1</span>,<span class="number">2</span>,<span class="number">1</span>)</span><br><span class="line">	plt.plot(dic_mouth.keys(), dic_mouth.values(),color=<span class="string">&#x27;red&#x27;</span>,marker=<span class="string">&#x27;o&#x27;</span>,markerfacecolor=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&#x27;mouth&#x27;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&#x27;hour&#x27;</span>)</span><br><span class="line">	plt.title(<span class="string">&#x27;Month duration curve&#x27;</span>)</span><br><span class="line">	plt.subplot(<span class="number">1</span>,<span class="number">2</span>,<span class="number">2</span>)</span><br><span class="line">	plt.plot(dic_week.keys(), dic_week.values(),color=<span class="string">&#x27;blue&#x27;</span>,marker=<span class="string">&#x27;o&#x27;</span>,markerfacecolor=<span class="string">&#x27;red&#x27;</span>)</span><br><span class="line">	plt.xlabel(<span class="string">&#x27;week&#x27;</span>)</span><br><span class="line">	plt.ylabel(<span class="string">&#x27;hour&#x27;</span>)</span><br><span class="line">	plt.title(<span class="string">&#x27;Week duration curve&#x27;</span>)</span><br><span class="line">	plt.show()</span><br><span class="line">    </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">test2</span>():</span></span><br><span class="line">	data = pd.read_csv(<span class="string">&#x27;Plants of forest.csv&#x27;</span>)</span><br><span class="line">	tree_type_analyse(data)</span><br><span class="line">	duration = tree_tag_analyse(data)</span><br><span class="line">	success_rate_analyse(data)</span><br><span class="line">	day_and_mouth_analyse(data,duration)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span>():</span></span><br><span class="line">	plt.rcParams[<span class="string">&#x27;font.sans-serif&#x27;</span>]=[<span class="string">&#x27;SimHei&#x27;</span>]	<span class="comment"># 解决中文显示问题</span></span><br><span class="line">	plt.rcParams[<span class="string">&#x27;axes.unicode_minus&#x27;</span>] = <span class="literal">False</span>  <span class="comment"># 解决负号显示问题</span></span><br><span class="line">	test2()</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">	main()</span><br></pre></td></tr></table></figure>

        </div>

        
            <section class="post-copyright">
                
                    <p class="copyright-item">
                        <span>Author:</span>
                        <span><a href="/about/">WD</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>Permalink:</span>
                        <span><a href="https://did321.gitee.io/2020/07/17/Forest%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E5%8F%8A%E5%8F%AF%E8%A7%86%E5%8C%96/">https://did321.gitee.io/2020/07/17/Forest%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E5%8F%8A%E5%8F%AF%E8%A7%86%E5%8C%96/</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>License:</span>
                        <span>Copyright (c) 2022 <a target="_blank" rel="noopener" href="http://creativecommons.org/licenses/by-nc/4.0/">CC-BY-NC-4.0</a> LICENSE</span>
                    </p>
                
                
                     <p class="copyright-item">
                         <span>Slogan:</span>
                         <span><a href="#">The blog is my giant.</a></span>
                     </p>
                

            </section>
        
        <section class="post-tags">
            <div>
                <span>Tag(s):</span>
                <span class="tag">
                    
                    
                        <a href="/tags/python/"># python</a>
                    
                        <a href="/tags/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/"># 数据分析</a>
                    
                        
                </span>
            </div>
            <div>
                <a href="javascript:window.history.back();">back</a>
                <span>· </span>
                <a href="/">home</a>
            </div>
        </section>
        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/2020/07/29/Python%E7%88%AC%E5%8F%96%E5%A4%A9%E6%B0%94%E6%95%B0%E6%8D%AE%E5%8F%8A%E5%8F%AF%E8%A7%86%E5%8C%96%E5%88%86%E6%9E%90/">Python爬取天气数据及可视化分析</a>
            
            
            <a class="next" rel="next" href="/2020/07/16/%E5%9F%BA%E4%BA%8Ejieba%E5%BA%93%E7%9A%84%E8%AF%8D%E9%A2%91%E5%88%86%E6%9E%90/">基于jieba库的词频分析</a>
            
        </section>
        <br>
        <br>
    
    <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
    <div id="vcomments"></div>
    <script>
        new Valine({
    el: '#vcomments' ,

    appId: 'JvFy3ebVLo2rUYgHaMweJyXX-MdYXbMMI',
    appKey: 'TCFxfjDAM8UmERPEgYXJmT40',
    serverURLs: 'https://JvFy3ebV.api.lncldglobal.com', 
    placeholder: '----评论区----留下你的评论，作者会定期回复！在昵称处填写QQ号可自动获取邮箱和QQ头像（保护QQ邮箱隐私）',
    enableQQ: true,
    requiredFields: ['nick'],
});
    </script>

    </article>
</div>

        </div>
        <footer id="footer" class="footer">
    <div class="copyright">
        <span>© WD | Powered by <a href="https://hexo.io" target="_blank">Hexo</a> & <a href="https://github.com/Siricee/hexo-theme-Chic" target="_blank">Chic</a></span>
    </div>
</footer>

    </div>
</body>

</html>
